﻿using StockMatch.Service.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Titan;

namespace StockMatch.Service
{
    public class DayWinProjectAccountService : ContextBoundObject
    {

        #region 增删改

        public bool Insert(DayWinProjectAccount projectAccount)
        {
            try
            {
                using (var cn = Environment.OpenSession())
                {
                    return cn.Insert(projectAccount) > 0;
                    //同时向审批表添加记录
                }
            }
            catch (Exception ex)
            {
                throw new StockException(ex.Message);
            }
        }

        public bool Update(DayWinProjectAccounts projectAccounts, params object[] updateProperty)
        {
            try
            {
                using (var cn = Environment.OpenSession())
                {
                    return cn.Update(projectAccounts, updateProperty) > 0;
                    //向审批表添加条记录
                }
            }
            catch (Exception ex)
            {
                throw new StockException(ex);
            }
        }

        public bool Delete(int projectAccountId)
        {
            try
            {
                using (var cn = Environment.OpenSession())
                {
                    DayWinProjectAccount projectAccount = new DayWinProjectAccount() { ProjectAccountId = projectAccountId };
                    return cn.Delete(projectAccount) > 0;//物理删除还是伪删除?

                    //删除审批表中的记录
                }
            }
            catch (Exception ex)
            {
                throw new StockException(ex.Message);
            }
        }

        #endregion


        #region 查询

        public DayWinProjectAccount GetProjectAccount(int projectAccountId)
        {
            try
            {
                using (var cn = Environment.OpenSession())
                {
                    DayWinProjectAccount projectAccount = new DayWinProjectAccount() { ProjectAccountId = projectAccountId };
                    if (cn.Select(projectAccount))
                    {
                        return projectAccount;
                    }
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw new StockException(ex.Message);
            }
        }

        public DayWinProjectAccounts GetProjectAccounts(QueryExpression query)
        {
            try
            {
                using (var cn = Environment.OpenSession())
                {
                    DayWinProjectAccounts projectAccounts = new DayWinProjectAccounts();
                    projectAccounts.TotalCount = cn.SelectCollection(projectAccounts.Items, query);
                    return projectAccounts;
                }
            }
            catch (Exception ex)
            {
                throw new StockException(ex.Message);
            }
        }

        #endregion
    }
}
